<?php

namespace App\Console\Commands;

use App\Models\Article;
use Illuminate\Console\Command;
use QL\QueryList;

class Jock extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'spider:jock';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        //目标地址
        $url="https://www.sohu.com/a/221358398_559229";
        //获取请求得到目标地址的数据
        $html=http_request($url);
        //采集规则
        $rules=[
            'body'=>['.article p','text']
        ];
        $data=QueryList::rules($rules)->html($html)->query()->getData();
        //得到数据入库
        foreach ($data as $item){
            \App\Models\Jock::create($item);
        }
        echo "OK\n";
    }
}
